package ai.rpc.core.model;

import cn.hutool.core.util.StrUtil;
import lombok.Data;

/**
 * @Author: mengyu
 * @Date: 2024/7/26
 */
@Data
public class ServiceMetaInfo {
    private String serviceName;
    private String serviceVersion = "1.0";
    private String serviceHost;
    private Integer servicePort;
    private String serviceGroup = "default"; // TODO 实现分组

    /**
     * 获取服务注册节点key
     * @return key
     */
    public String getServiceKey(){
        return String.format("%s:%s",serviceName,serviceVersion);
    }

    /**
     * 获取服务注册节点键名
     * @return 节点键名
     */
    public String getServiceNodeKey(){
        return String.format("%s/%s:%s",getServiceKey(),serviceHost,servicePort);
    }

    /**
     * 获取服务提供方地址
     * @return 地址
     */
    public String getServiceAddress(){
        if(!StrUtil.contains(serviceHost,"http")){
            return String.format("http://%s:%s",serviceHost,servicePort);
        }
        return String.format("%s:%s",serviceHost,servicePort);
    }
}
